﻿<%@ Page Language="C#" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Import Namespace="Microsoft.SharePoint.Utilities" %>
<%@ Import Namespace="Microsoft.SharePoint.Administration" %>

<script runat="server" language="C#">
private void Page_Load()
{
    string url = Request.QueryString["url"];
    
    if (url.StartsWith("/12/TEMPLATE/LAYOUTS"))
    {
        url = "/_layouts/" + url.Substring(20);
        Response.Redirect(url);
    }
    else if (url.StartsWith("/12/TEMPLATE/Features"))
    {
        string feature_name = url.Substring(22);
        feature_name = feature_name.Substring(0, feature_name.IndexOf("/"));

        SPFeatureDefinition feature_def = SPFarm.Local.FeatureDefinitions[feature_name];
        SPElementDefinitionCollection element_def_coll = feature_def.GetElementDefinitions(new System.Globalization.CultureInfo(1033));

        foreach (SPElementDefinition def in element_def_coll)
        {
            if (def.ElementType == "Module")
            {
                url = "/" + def.XmlDefinition.Attributes["Url"].Value + url.Substring(url.LastIndexOf("/"));
                Response.Redirect(url);
            }
        }
        
        
    }
}
</script>